const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const StudentLesson = sequelize.define('StudentLesson', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  student_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '学生ID'
  },
  lesson_title: {
    type: DataTypes.STRING(200),
    allowNull: false,
    comment: '课程标题'
  },
  lesson_date: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '上课日期'
  },
  duration: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '上课时长（分钟）'
  },
  replay_url: {
    type: DataTypes.STRING(500),
    allowNull: true,
    comment: '录播链接'
  },
  notes: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '备注'
  },
  created_by: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '创建人ID（管理员）'
  },
  created_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    comment: '创建时间'
  },
  updated_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    comment: '更新时间'
  }
}, {
  tableName: 'student_lessons',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  indexes: [
    {
      fields: ['student_id']
    },
    {
      fields: ['lesson_date']
    },
    {
      fields: ['created_by']
    }
  ]
});

module.exports = StudentLesson; 